package test0.dao.dbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DatabaseConnection {
//	private static final String DBDRIVER="org.git.mm.mysql.Driver";
	private static final String DBDRIVER="com.mysql.jdbc.Driver";
	private static final String DBURL="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8";
	//Java插入中文到数据库的中文变成问号，在url后面添加参数
	//url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8
	private static final String DBUSER="root";
	private static final String DBPASSWORD="123456";
	private Connection conn=null;
	public DatabaseConnection() {
		try {
			Class.forName(DBDRIVER);
			this.conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);
		} catch (ClassNotFoundException | SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public Connection getConnection() {
		return this.conn;
	}
	public void close() throws Exception {
		if (this.conn!=null) {
			this.conn.close();
		}
	}
}
